package com.utils;

import lombok.Data;

import java.util.List;

@Data
public class PageInfo<T> {
    private int pageNum; // 当前页码
    private int pageSize; // 每页数量
    private long total; // 总记录数
    private int pages; // 总页数
    private List<T> list; // 当前页的数据列表

    public PageInfo(int pageNum, int pageSize, long total, List<T> list) {
        if (list == null) {
            throw new IllegalArgumentException("List cannot be null");
        }
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.total = total;
        this.list = list;
        this.pages = (int) ((total + pageSize - 1) / pageSize);
    }

    // 判断是否为第一页
    public boolean isFirstPage() {
        return pageNum == 1;
    }

    // 判断是否为最后一页
    public boolean isLastPage() {
        return pageNum == pages;
    }
}